//
//  JWModeifyNickNameViewController.m
//  见闻新闻
//
//  Created by brother on 16/3/15.
//  Copyright © 2016年 JoanBoat. All rights reserved.
//

#import "JWModeifyNickNameViewController.h"

#import "JWUserModel.h"

#import "JWUpUserDataTools.h"

@interface JWModeifyNickNameViewController ()
@property (weak, nonatomic) IBOutlet UITextField *modifyNicknameText;

@end

@implementation JWModeifyNickNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
     [self.modifyNicknameText becomeFirstResponder];
    
    self.view.backgroundColor = [UIColor grayColor];
    
    
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)back:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (IBAction)modify:(id)sender {
    
    if (![self.modifyNicknameText.text isEqualToString:@""] ) {
        
        NSString *urlpath = [baseUrl stringByAppendingString:@"/User/updateInfo"];
        
        
        AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
        
        
        NSUserDefaults *UserDefaults = [NSUserDefaults standardUserDefaults];
        
        NSDictionary *tempDic = [UserDefaults objectForKey:UserInfo];
        
        JWUserModel *userModel = [JWUserModel mj_objectWithKeyValues:tempDic];
        
        NSLog(@"%@",userModel.user_id);
        
        //    self.modifyNicknameText.text = userModel.user_nickname;
        
        NSDictionary *parameters = @{@"user_id" : userModel.user_id,
                                     @"user_nickname":self.modifyNicknameText.text
                                     };
        
        
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        
        hud.labelText = @"正在修改";
        
        [manger POST:urlpath parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            hud.hidden = YES;
            
            [JWUpUserDataTools updataToModel];
            
            
            
            
            [[[UIAlertView alloc] initWithTitle:@"提示" message:responseObject[@"data"] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]show];

            
         
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            hud.hidden = YES;
            NSLog(@"%@",error);
        }];
        
        [self.modifyNicknameText resignFirstResponder];
    }else {
    
        [[[UIAlertView alloc]initWithTitle:@"提示" message:@"昵称还没填写" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil]show];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
